<script type="text/javascript">
/** 创建笔记基础 **/
function createNote0(title, type) {
    xnote.prompt(title, "", function (noteTitle) {
        var createOption = {};
        createOption.name = noteTitle;
        createOption.parent_id = "{{parent_id}}";
        createOption.type = type;
        createOption._format = "json";
        $.post("/note/create", createOption, function (resp) {
            if (resp.code == "success") {
                window.location.href = resp.url;
            } else {
                alert(title + "失败:" + resp.message);
            }
        }).fail(function (e) {
            console.error(title + "失败", e);
            alert(title + "失败:" + e);
        });
    });
}

/** 创建相册 **/
function createGallery() {
    createNote0("新建相册", "gallery");
}

/** 新建文档 **/
function createDocument() {
    createNote0("新建文档", "md");
}

/** 创建清单 **/
function createList() {
    createNote0("新建清单", "list");
}

/** 创建表格 **/
function createTable() {
    createNote0("新建表格", "csv");
}

/** 创建记事 **/
function createLog() {
    window.location.href = "/note/add?type=log&parent_id={{parent_id}}";
}

function createLogOld() {
    var title = "创建日志";
    var createOption = {};
    createOption.parent_id = "{{parent_id}}";
    createOption.type = "text";
    createOption._format = "json";

    $.post("/note/create", createOption, function (resp) {
        if (resp.code == "success") {
            window.location.href = resp.url;
        } else {
            xnote.alert(title + "失败:" + resp.message);
        }
    }).fail(function (e) {
        console.error(title + "失败", e);
        xnote.alert(title + "失败:" + e);
    });
}
/** 创建分组 **/
function createGroup() {
    var opName = "新建笔记本";
    xnote.prompt(opName, "", function (noteTitle) {
        var createOption = {};
        createOption.name = noteTitle;
        createOption.parent_id = "{{parent_id}}";
        createOption.type = "group";
        createOption._format = "json";
        $.post("/note/create", createOption, function (resp) {
            if (resp.code == "success") {
                window.location = resp.url;
            } else {
                xnote.alert(opName + "失败:" + resp.message);
            }
        }).fail(function (e) {
            console.error(opName + "失败", e);
            xnote.alert(opName + "失败:" + e);
        });
    });
}

/** 上传文件 **/
function uploadFile() {

}

xnote.createNotebook = function () {
    return createGroup();
}
</script>
